﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Collections.ObjectModel;

namespace Viewer.ChucNang.UserControls
{
    public partial class NguoiDung : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [DirectMethod]
        public void ReloadData()
        {
            BindData();
        }
        public void BindData()
        {
            this.storeNguoiDung.DataSource = (new BusinessObject.BusinessEntities.QUNguoiDung()).LoadData();
            this.storeNguoiDung.DataBind();
            this.PagingToolbar1.PageSize = 10;
            Ext.Net.X.AddScript("SynDataBetween2Store();");
        }
        //protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
        //{
        //    List<BusinessObject.BusinessEntities.QUNguoiDung> data = (new BusinessObject.BusinessEntities.QUNguoiDung()).GetAll();

        //    string s = e.Parameters[this.GridFilters1.ParamPrefix];
        //    //or with hardcoding - string s = e.Parameters["gridfilters"];;


        //    //-- start filtering ------------------------------------------------------------
        //    if (!string.IsNullOrEmpty(s))
        //    {
        //        FilterConditions fc = new FilterConditions(s);

        //        foreach (FilterCondition condition in fc.Conditions)
        //        {
        //            Comparison comparison = condition.Comparison;
        //            string field = condition.Name;
        //            FilterType type = condition.FilterType;

        //            object value;
        //            switch (condition.FilterType)
        //            {                       
        //                case FilterType.String:
        //                    value = condition.Value;
        //                    break;
        //                default:
        //                    throw new ArgumentOutOfRangeException();
        //            }

        //            data.RemoveAll(
        //                item =>
        //                {
        //                    object oValue = item.GetType().GetProperty(field).GetValue(item, null);
        //                    IComparable cItem = oValue as IComparable;

        //                    switch (comparison)
        //                    {
        //                        case Comparison.Eq:

        //                            switch (type)
        //                            {
        //                                case FilterType.List:
        //                                    return !(value as ReadOnlyCollection<string>).Contains(oValue.ToString());
        //                                case FilterType.String:
        //                                    return !oValue.ToString().StartsWith(value.ToString());
        //                                default:
        //                                    return !cItem.Equals(value);
        //                            }

        //                        case Comparison.Gt:
        //                            return cItem.CompareTo(value) < 1;
        //                        case Comparison.Lt:
        //                            return cItem.CompareTo(value) > -1;
        //                        default:
        //                            throw new ArgumentOutOfRangeException();
        //                    }
        //                }
        //            );
        //        }
        //    }
        //    //-- end filtering ------------------------------------------------------------


        //    //-- start sorting ------------------------------------------------------------
          
        //    //-- end sorting ------------------------------------------------------------


        //    //-- start paging ------------------------------------------------------------
        //    var limit = e.Limit;

        //    if ((e.Start + e.Limit) > data.Count)
        //    {
        //        limit = data.Count - e.Start;
        //    }

        //    List<BusinessObject.BusinessEntities.QUNguoiDung> rangeData = (e.Start < 0 || limit < 0) ? data : data.GetRange(e.Start, limit);
        //    //-- end paging ------------------------------------------------------------

        //    //The Total can be set in RefreshData event as below
        //    //or (Store1.Proxy.Proxy as PageProxy).Total in anywhere
        //    //Please pay attention that the Total make a sence only during DirectEvent because
        //    //the Store with PageProxy get/refresh data using ajax request

        //    e.Total = data.Count;

        //    this.grdNguoiDung.GetStore().DataSource = rangeData;
        //}
    }
}